#! /bin/sh

get_k3d() {
    k3d_version=$(curl -s https://api.github.com/repos/k3d-io/k3d/tags | jq -r '.[0].name')
    echo "k3d_version: ${k3d_version}"
    cli="k3d"
    bin_path="/usr/local/bin"
    file_name="k3d-linux-amd64"
    sudo rm -rf ${bin_path}/${cli}

    # k3d_version=$(curl -s https://api.github.com/repos/k3d-io/k3d/tags | jq -r '.[0].name')
    # wget https://rancher-mirror.rancher.cn/k3d/${k3d_version}/k3d-linux-amd64
    wget https://ghproxy.net/https://github.com/k3d-io/k3d/releases/download/${k3d_version}/${file_name}
    mv ${file_name} ${cli}
    chmod +x ${cli}
    sudo mv ${cli} ${bin_path}
}
get_k3d
